package com.net.oil.user.presenter;

import com.net.oil.base.BasePresenter;
import com.net.oil.user.bean.CheckPhoneBean;
import com.net.oil.user.bean.RegisterBean;
import com.net.oil.user.bean.UserInfo;
import com.net.oil.user.contract.RegisterContract;
import com.net.oil.user.model.RegisterModel;

/**
 * 作者：lch
 * 时间：2018/3/14:9:53
 * 邮箱：245850413@qq.com
 * 说明：
 */

public class RegisterPresenter extends BasePresenter<RegisterContract.View> implements RegisterContract.Presenter {

    private RegisterContract.View view;
    private RegisterContract.Model model;

    public RegisterPresenter(RegisterContract.View view) {
        this.view = view;
        this.model = new RegisterModel(this);
    }

    @Override
    protected void unSubscribe() {
        model.unSubscribe();
    }

    /**
     * 验证手机号是否注册
     * @param phone 手机号
     */
    @Override
    public void checkPhone(String phone) {
        model.checkPhone(phone);
    }

    /**
     * 验证手机号成功
     * @param checkPhoneBean  返回数据
     */
    @Override
    public void checkPhoneSuccess(CheckPhoneBean checkPhoneBean) {
        view.checkPhoneSuccess(checkPhoneBean);
    }

    /**
     * 验证手机号失败
     */
    @Override
    public void checkPhoneFailed() {
        view.checkPhoneFailed();
    }

    /**
     * 获取手机验证码
     * @param phone 手机号
     * @param ptt   是否是语音
     */
    @Override
    public void getPhoneCodeCode(String phone, boolean ptt) {
        model.getPhoneCode(phone, ptt);
    }

    @Override
    public void getPhoneCodeSuccess() {
        view.getPhoneCodeSuccess();
    }

    @Override
    public void getPhoneCodeFailed() {
        view.getPhoneCodeFailed();
    }

    /**
     * 验证手机验证码
     * @param phone 手机号
     * @param code  验证码
     */
    @Override
    public void verifyCode(String phone, String code) {
        model.verifyCode(phone, code);
    }

    /**
     * 严重手机验证码成功
     */
    @Override
    public void verifyCodeSuccess() {
        view.verifyCodeSuccess();
    }

    /**
     * 验证手机验证码失败
     */
    @Override
    public void verifyCodeFailed() {
        view.verifyCodeFailed();
    }

    @Override
    public void register(String phone, String password, String nickname, String invitationPhone) {
        model.register(phone, password, nickname, invitationPhone);
    }

    /**
     * 注册成功
     * @param registerBean  返回的数据
     */
    @Override
    public void registerSuccess(RegisterBean registerBean) {
        view.registerSuccess(registerBean);
    }

    /**
     * 注册失败
     */
    @Override
    public void registerFailed() {
        view.registerFailed();
    }

    @Override
    public void login(String phone, String password) {
        model.login(phone, password);
    }

    @Override
    public void loginSuccess(UserInfo userInfo) {
        view.loginSuccess(userInfo);
    }

    @Override
    public void loginFailed() {
        view.loginFailed();
    }

    @Override
    public void registerV2(String phone, String password, String nickname, String invitationPhone, String email) {
        model.registerV2(phone, password, nickname, invitationPhone, email);
    }

    @Override
    public void registerV2Success(UserInfo userInfo) {
        view.registerV2Success(userInfo);
    }

    @Override
    public void registerV2Failed() {
        view.registerV2Failed();
    }
}
